import { connect } from 'dva';
import _ from 'lodash';
import router from 'umi/router';
import config from '../../config/config';
import * as utils from '@/utils/menuTree';

const HomePage = props => {
  const { menus } = props.Permissions;
  if (menus && menus.length > 0) {
    const { routes } = config;
    const cloneRoutes = _.cloneDeep(routes);
    const url = utils.getFirstPage(cloneRoutes, menus);
    router.replace(url);
  }
  return null;
};

export default connect(({ Permissions }) => ({
  Permissions,
}))(HomePage);
